package cn.com.jslh.boarpro.main;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.CheckBox;
import android.widget.EditText;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.com.jslh.boarpro.R;
import cn.com.jslh.boarpro.main.presenter.LoginPresenterImpl;
import cn.com.jslh.boarpro.main.presenter.UpDataAppPresenterImpl;
import cn.com.jslh.boarpro.main.view.view.LoginView;
import cn.com.jslh.boarpro.util.template.TemplateFactory;

public class LoginActivity extends AppCompatActivity implements LoginView{
    @BindView(R.id.username)
    EditText username;
    @BindView(R.id.passEdit)
    EditText passEdit;
    @BindView(R.id.isremenber)
    CheckBox isremenber;

    private LoginPresenterImpl loginPresenter;
    private UpDataAppPresenterImpl presenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        ButterKnife.bind(this);
        presenter=new UpDataAppPresenterImpl(this);
        presenter.getData();
        loginPresenter = new LoginPresenterImpl(this,this);
        loginPresenter.initUserAndPass(); //初始化用户名密码
    }


    @OnClick(R.id.loginBtn)
    public void onViewClicked() {
        if(username.getText().toString().equals("")){
            username.setError("用户名不能为空");
            return;
        }else if(passEdit.getText().toString().equals("")){
            passEdit.setError("密码不能为空");
            return;
        }
        loginPresenter.rember(isremenber.isChecked(),username.getText().toString(),passEdit.getText().toString());
        loginPresenter.doLogin(username.getText().toString(),passEdit.getText().toString());
    }

    @Override
    public void initUserAndPass(String user, String pass) {
        username.setText(user);
        passEdit.setText(pass);
    }



}
